package com.byxy.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.byxy.shop.entity.User;

/**
 * @author 廖善椅
 * @ClassName UserDao
 * @Description Dao接口
 * @date 2020年5月17日
 */

public interface UserDao {

	@Select("select * from tb_newbee_mall_user where login_name = #{loginName} and password_md5 = #{password}")
	User selectByNameAndPassword(@Param("loginName") String loginName, @Param("password") String password);

	@Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
	@Insert("insert into tb_newbee_mall_user(user_id,nick_name,login_name,password_md5,introduce_sign,address,is_deleted,locked_flag,create_time) values "
			+ "(#{userId},#{nickName},#{loginName},#{passwordMd5},#{introduceSign},#{address},#{isDeleted},#{lockedFlag},#{createTime})")
	Integer save(User user);
	
	@Select("select * from tb_newbee_mall_user where login_name = #{loginName}")
	List<User> getByName(String loginName);

	@Select("select * from tb_newbee_mall_user where user_id = #{id} and is_deleted = 0")
	User getById(Integer userId);

	@Update("update tb_newbee_mall_user set nick_name=#{nickName},introduce_sign=#{introduceSign},address=#{address} where user_id=#{userId}")
	int updateByPrimaryKeySelective(User user);

}
